import Vue from 'vue'
import Vuex from 'vuex'
import {http} from '@/utils/luch-request/index.js' // 全局挂载引入，配置相关在该index.js文件里修改
Vue.use(Vuex)

const store = new Vuex.Store({
	namespaced: true,
	state: {
		menuListIdx:0,
		userInfo: {},
		menuList:[
			{
				optIcon:"../../static/imgs/gongzuo.png",
				defIcon:"../../static/imgs/gongzuo1.png",
				url:"/pages/home/home",
				name:"工作",
			},
			{
				optIcon:"../../static/imgs/xiaoxi.png",
				defIcon:"../../static/imgs/xiaoxi1.png",
				url:"/pages/message/message",
				name:"消息",
			},
			{
				optIcon:"../../static/imgs/wode.png",
				defIcon:"../../static/imgs/wode1.png",
				url:"/pages/user/user",
				name:"我的",
			},
		]
	},
	mutations: {
		saveData(state, { payload ,callback}) {
			Object.assign(state, {...payload});
			if(callback) callback(state)
		},
	},
	actions: {
	
		async requestData({ commit, state }, _){
			const _data = await http[_.method || 'get'](_.url,{
				..._.params
			})
			let __data = [];
			_data.data.data.map(function(item,idx){
				__data.push({
					name:item[_.keyName || 'name'],
					id:item[_.idName || 'id'],
				})
			})
			commit({
			    type:'saveData',
			    payload:{
			        [_.name]:__data,
			    }
			})
		},
	}
})

export default store
